package com.cloud.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class KafkaConsumer2 {
    @KafkaListener(topics = {"testTopic"}, groupId = "default_consumer_group")
    public void listener(ConsumerRecord<String, String> record) {
        //获取消息
        String message = record.value();
        //消息偏移量
        long offset = record.offset();
        System.out.println("KafkaConsumer2读取的消息：" + message + "\n当前偏移量：" + offset);
    }
}
